﻿using Microsoft.EntityFrameworkCore;

namespace DataBase.DBmodels;

public partial class BushingPressContext : DbContext
{
    public BushingPressContext()
    {
    }

    public BushingPressContext(DbContextOptions<BushingPressContext> options)
        : base(options)
    {
    }

    public virtual DbSet<BackupInfo> BackupInfos { get; set; }

    public virtual DbSet<ButtonControl> ButtonControls { get; set; }

    public virtual DbSet<Craft> Crafts { get; set; }

    public virtual DbSet<Decision> Decisions { get; set; }

    public virtual DbSet<DecisionType> DecisionTypes { get; set; }

    public virtual DbSet<Electricity> Electricitys { get; set; }

    public virtual DbSet<ProductionData> ProductionData { get; set; }

    public virtual DbSet<RolePermission> RolePermissions { get; set; }

    public virtual DbSet<Setting> Settings { get; set; }

    public virtual DbSet<User> Users { get; set; }

    public virtual DbSet<UserRoleRelation> UserRoleRelations { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseMySql("server=192.168.2.36;port=3306;database=BushingPress;uid=root;pwd=123456", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.33-mysql"));

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_0900_ai_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<BackupInfo>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("BackupInfo", tb => tb.HasComment("备份信息表"));

            entity.Property(e => e.Id)
                .HasComment("主键")
                .HasColumnName("id");
            entity.Property(e => e.BackupTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("备份的时间")
                .HasColumnType("timestamp")
                .HasColumnName("backup_time");
            entity.Property(e => e.BackupUser)
                .HasMaxLength(255)
                .HasComment("备份者")
                .HasColumnName("backup_user");
            entity.Property(e => e.FileName)
                .HasMaxLength(255)
                .HasComment("备份文件名称")
                .HasColumnName("file_name");
            entity.Property(e => e.FileSize)
                .HasComment("备份文件的大小")
                .HasColumnName("file_size");
            entity.Property(e => e.FolderPath)
                .HasMaxLength(255)
                .HasComment("备份的文件夹路径")
                .HasColumnName("folder_path");
            entity.Property(e => e.Remarks)
                .HasMaxLength(255)
                .HasComment("备注")
                .HasColumnName("remarks");
        });

        modelBuilder.Entity<ButtonControl>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("ButtonControl", tb => tb.HasComment("按钮控件表"));

            entity.Property(e => e.Id)
                .HasComment("主键，自动递增")
                .HasColumnName("ID");
            entity.Property(e => e.ControlName)
                .HasMaxLength(50)
                .HasComment("按钮的名称");
            entity.Property(e => e.CreatedTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("创建时间，系统自动填充")
                .HasColumnType("datetime");
            entity.Property(e => e.FeatureName)
                .HasMaxLength(50)
                .HasComment("按钮所在的功能模块");
            entity.Property(e => e.IsEnabled)
                .HasDefaultValueSql("'1'")
                .HasComment("是否启用，1表示启用，0表示禁用");
            entity.Property(e => e.ModifiedTime)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.PageName)
                .HasMaxLength(50)
                .HasComment("按钮所在的页面");
        });

        modelBuilder.Entity<Craft>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("Craft");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Project).HasMaxLength(255);
            entity.Property(e => e.ShowType).HasMaxLength(255);
        });


   

    

        modelBuilder.Entity<Electricity>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("Electricity");
         
        });

        modelBuilder.Entity<ProductionData>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.Property(e => e.Id)
                .HasComment("SN_ID")
                .HasColumnName("ID");
            entity.Property(e => e.CreateTime)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.CylinderNo)
                .HasMaxLength(8)
                .HasComment("电缸编号");
            entity.Property(e => e.MaxPositionValue).HasComment("最大位移值");
            entity.Property(e => e.MaxPressureValue).HasComment("最大压力值");
            entity.Property(e => e.Result).HasComment("判断结果，0表示\"OK\",1表示\"NG\"");
            entity.Property(e => e.Sn)
                .HasMaxLength(50)
                .HasComment("SN编号")
                .HasColumnName("SN");
            entity.Property(e => e.NowTime)
                .HasMaxLength(32)
                .HasComment("衬套版本");
        });

        modelBuilder.Entity<RolePermission>(entity =>
        {
            entity.HasKey(e => e.RoleId).HasName("PRIMARY");

            entity.ToTable("RolePermission", tb => tb.HasComment("角色权限表"));

            entity.Property(e => e.RoleId)
                .HasComment("主键，自动递增")
                .HasColumnName("RoleID");
            entity.Property(e => e.ControlName)
                .HasMaxLength(50)
                .HasComment("按钮控件名称");
            entity.Property(e => e.PermissionCode)
                .HasMaxLength(50)
                .HasComment("权限编码");
            entity.Property(e => e.PermissionName)
                .HasMaxLength(100)
                .HasComment("权限名称");
            entity.Property(e => e.RoleLevel)
                .HasDefaultValueSql("'3'")
                .HasComment("权限等级，普通用户是3，admin是2，administrator是1");
        });

        modelBuilder.Entity<Setting>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.Property(e => e.Key).HasMaxLength(255);
            entity.Property(e => e.Value).HasMaxLength(255);
        });

        modelBuilder.Entity<User>(entity =>
        {
            entity.HasKey(e => e.UserId).HasName("PRIMARY");

            entity.ToTable("User", tb => tb.HasComment("用户表"));

            entity.HasIndex(e => e.UserName, "Account").IsUnique();

            entity.Property(e => e.UserId)
                .HasComment("主键，自动递增")
                .HasColumnName("UserID");
            entity.Property(e => e.CreatedTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("创建时间，系统自动填充")
                .HasColumnType("datetime");
            entity.Property(e => e.Email)
                .HasMaxLength(100)
                .HasComment("用户邮箱");
            entity.Property(e => e.FullName)
                .HasMaxLength(50)
                .HasComment("用户姓名");
            entity.Property(e => e.IsEnabled)
                .HasDefaultValueSql("'1'")
                .HasComment("是否启用，1表示启用，0表示禁用");
            entity.Property(e => e.ModifiedTime)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.Password)
                .HasMaxLength(50)
                .HasComment("密码");
            entity.Property(e => e.PhoneNumber)
                .HasMaxLength(20)
                .HasComment("手机号码");
            entity.Property(e => e.Remark)
                .HasMaxLength(200)
                .HasComment("备注");
            entity.Property(e => e.UserName)
                .HasMaxLength(50)
                .HasComment("用户名");
        });

        modelBuilder.Entity<UserRoleRelation>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PRIMARY");

            entity.ToTable("UserRoleRelation", tb => tb.HasComment("用户角色关联表"));

            entity.HasIndex(e => e.RoleId, "RoleId");

            entity.HasIndex(e => e.UserId, "UserId");

            entity.Property(e => e.Id)
                .HasComment("主键，自动递增")
                .HasColumnName("ID");
            entity.Property(e => e.CreatedTime)
                .HasDefaultValueSql("CURRENT_TIMESTAMP")
                .HasComment("创建时间，系统自动填充")
                .HasColumnType("datetime");
            entity.Property(e => e.ModifiedTime)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.RoleId).HasComment("关联角色表的主键");
            entity.Property(e => e.UserId).HasComment("关联用户表的键");
           
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
